package leetcode;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public static ListNode createByArray(int[] nums) {
        int len = nums.length;
        ListNode head = new ListNode(-1);
        ListNode p = head;
        while (len > 0) {
            p.next = new ListNode(nums[nums.length - len]);
            p = p.next;
            len--;
        }
        return head.next;
    }

    public static void print(ListNode head) {
        while (head != null) {
            System.out.print(head.val + ",");
            head = head.next;
        }
    }
}
